//
//  ScenicListCell.m
//  TravelToHelp
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 冯贵宾. All rights reserved.
//

#import "ScenicListCell.h"

@interface ScenicListCell ()

@property (nonatomic, strong) UIImageView *photoView;
@property (nonatomic, strong) UILabel *titleLable;
@property (nonatomic, strong) UILabel *contenLable;
@property (nonatomic, strong) NSMutableArray *imageArray;

@end

@implementation ScenicListCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addSubViews];
    }
    return self;
}

- (void)addSubViews
{
    // 背景图片
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:CGRectMake(5, 2, kScreenWidth - 10, 124)];
//    backImage.layer.cornerRadius = 10;
//    backImage.layer.masksToBounds = YES;
    backImage.image = [UIImage imageNamed:@"ScenicCellBack"];
    [self.contentView addSubview:backImage];
    
    // 设置图片的view
    self.photoView = [[UIImageView alloc] initWithFrame:CGRectMake(5, 5, 114, 114)];
    self.photoView.backgroundColor = [UIColor whiteColor];
    [backImage addSubview:self.photoView];
    
    // titleLable
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(self.photoView.right + 10, self.photoView.top + 5, backImage.width - self.photoView.right - 10, 30)];
    self.titleLable.font = [UIFont systemFontOfSize:20];
    [backImage addSubview:self.titleLable];
    
    // contentLable
    self.contenLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom, self.titleLable.width, 50)];
    self.contenLable.font = [UIFont systemFontOfSize:15];
    self.contenLable.numberOfLines = 0;
    [backImage addSubview:self.contenLable];

    UILabel *starLable = [[UILabel alloc] initWithFrame:CGRectMake(backImage.width - 120, self.contenLable.bottom + 5, 30, 20)];
    starLable.text = @"评级:";
    starLable.font = [UIFont systemFontOfSize:12];
    starLable.textAlignment = NSTextAlignmentRight;
    [backImage addSubview:starLable];
    
    // 添加星的imagView
    for (int i = 0; i < 5; i++) {
        UIImageView *starImageView = [[UIImageView alloc] initWithFrame:CGRectMake(starLable.right + i * 14, starLable.top + 3, 14, 14)];
        [backImage addSubview:starImageView];
        [self.imageArray addObject:starImageView];
    }
     
}

- (void)setModel:(ScenicListModel *)model
{
    self.titleLable.text = [NSString stringWithFormat:@"%@", model.Name];
    self.contenLable.text = [NSString stringWithFormat:@"%@", model.Foreword];
    [self.photoView sd_setImageWithURL:[NSURL URLWithString:model.NewPic] placeholderImage:[UIImage imageNamed:@"placeholderF.png"]];
    if (self.imageArray.count == 5) {
        for (UIImageView *ImaView in self.imageArray) {
            ImaView.image = [UIImage imageNamed:@""];
        }
        
        NSInteger count = model.ID % 4 + 1;
        if (count <= 2) {
            count = 3;
        } else {
            count++;
        }
        for (int i = 0; i < count; i++) {
            UIImageView *starImage = self.imageArray[i];
            starImage.image = [UIImage imageNamed:@"ScenicLike"];
        }
    }
}

- (NSMutableArray *)imageArray
{
    if (!_imageArray) {
        _imageArray = [NSMutableArray array];
    }
    return _imageArray;
}












- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end














